package com.decent.controller;

import java.math.BigDecimal;

import com.decent.enums.enums.StockStatusEnum;
import com.decent.enums.enums.StockTypeEnum;
import com.decent.enums.enums.StockVersionTypeEnum;

import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.Random;

import com.decent.enums.enums.StockLanguageTypeEnum;

import com.decent.dao.StockMapper;
import com.decent.entity.Stock;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 王雪杰
 * @date 2021/11/20 8:56
 */
@RestController
@RequestMapping("stock")
public class StockController {
    @Resource
    private StockMapper stockMapper;

    @RequestMapping("create")
    public String create() {
        StockTypeEnum[] stockTypeEnums = StockTypeEnum.values();
        StockLanguageTypeEnum[] languageTypeEnums = StockLanguageTypeEnum.values();
        StockVersionTypeEnum[] versionTypeEnums = StockVersionTypeEnum.values();
        StockStatusEnum[] stockStatusEnums = StockStatusEnum.values();
        long l = System.currentTimeMillis();
        for (int i = 9319; i < 30000; i++) {
            Stock stock = new Stock();
            stock.setId((long) i);
            stock.setOrderId(1L);
            stock.setProductId(1L);
            stock.setCost(BigDecimal.valueOf((Math.random() * 1000)).divide(BigDecimal.ONE, 2, RoundingMode.HALF_DOWN));
            stock.setCreateTime(LocalDateTime.now());
            stock.setInTime(LocalDateTime.now());
            stock.setStockNo(RandomStringUtils.randomAlphanumeric(9));
            stock.setStockType(StockTypeEnum.NORMAL);
            stock.setLanguageType(languageTypeEnums[BigDecimal.valueOf((Math.random() * 4)).intValue()]);
            stock.setVersionType(versionTypeEnums[BigDecimal.valueOf((Math.random() * 2)).intValue()]);
            stock.setStockStatus(stockStatusEnums[BigDecimal.valueOf((Math.random() * 2)).intValue()]);
            stock.setLocationId(1L);
            stock.setShelvesId(1L);

            stockMapper.insert(stock);

        }
        System.out.println(System.currentTimeMillis() - l);
        return "OK";
    }
}
